home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12874 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Problem w/ VC 4.1 and the Deadly Diamond
  5. Date: 22 Mar 1996 01:12:58 GMT
  6. Organization: Borland International
  7. Message-ID: <4isuqq$b26@druid.borland.com>
  8. References: <4iqmgd$fuk@mark.ucdavis.edu>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4iqmgd$fuk@mark.ucdavis.edu>, ez055808@peseta.ucdavis.edu says...
  15. >
  16. >The following code doesn't compile under VC 4.1 (or 4.0) (I haven't tried it 
  17. >yet with other compilers):
  18. >
  19. >---------------------------------------------------------------
  20. >class A
  21. >{
  22. >public:
  23. >  A() { }
  24. >  virtual ~A() { }
  25. >};
  26. >
  27. >class B: virtual public A
  28. >{
  29. >public:
  30. >  B();
  31. >  virtual ~B() { }
  32. >};
  33. >
  34. >B::B(): A()
  35. >{
  36. >}
  37. >
  38. >class C: virtual public A
  39. >{
  40. >public:
  41. >  C();
  42. >  virtual ~C() { }
  43. >};
  44. >
  45. >C::C(): A()
  46. >{
  47. >}
  48. >
  49. >class D: public B, public C
  50. >{
  51. >public:
  52. >  D();
  53. >  virtual ~D() { }
  54. >};
  55. >
  56. >D::D(): B(), C()
  57. >{
  58. >}
  59. >
  60. >
  61. >class TestClass: public D
  62. >{
  63. >public:
  64. >  TestClass();
  65. >  virtual ~TestClass() { }
  66. >};
  67. >
  68. >TestClass::TestClass(): D()
  69. >{
  70. >}
  71. >
  72. >
  73. >void
  74. >testFunc1(const TestClass t)
  75. >{
  76. >}
  77. >
  78. >void
  79. >testFunc2()
  80. >{
  81. >  TestClass t;
  82. >  testFunc1(t);
  83. >}
  84. >
  85. >void
  86. >main(void)
  87. >{
  88. >  testFunc2();
  89. >}
  90. >
  91. >------------------------------------------------------------------
  92. >The call to testFunc1() gives the following error message:
  93. >
  94. >error C2662: '__vbaseDtor' : cannot convert 'this' pointer from 'const class
  95. >TestClass *' to 'class TestClass *const '
  96. >
  97. >If I change the parameter in testFunc1() to a ref, i.e. const TestClass& t, 
  98. >then it compiles fine.
  99. >
  100. >Of course, it should be passed by reference; but I don't understand why I'm 
  101. >getting this error. If I un-virtual the inheritance of B and C from A (thus 
  102. >avoiding the deadly diamond, but causing other headaches), then no compiler 
  103. >error. 
  104. >
  105. >What gives???
  106.  
  107. The code is legal. BC++ 5.0 compiles it.
  108.  
  109.